package com.fearless.dao.impl;


import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;

import com.fearless.entity.MessageEntity;
import com.fearless.util.DBManager;
import com.fearless.util.DateUtil;
import com.fearless.util.QueryResult;

public class MessageDaoImpl {
	
	public ArrayList<MessageEntity> messageAdminList(){
		ArrayList<MessageEntity> alist= new ArrayList<MessageEntity>();
	    String sqlString="select id,create_time,name,phone,email,content,show_home,note,update_time from message order by update_time desc";
	    QueryResult rSet=DBManager.executeQuery(sqlString);
	      if (rSet!=null) {
	        try {
	          while (rSet.rs.next()) {
	        	  alist.add(new MessageEntity(rSet.rs.getInt("id"),
	  	        			rSet.rs.getString("create_time"),
	  	            		rSet.rs.getString("name"),
	  	            		rSet.rs.getString("phone"),rSet.rs.getString("email"),
	  	            		rSet.rs.getString("content"),
	  	            		rSet.rs.getString("show_home"),
	  	            		rSet.rs.getString("note"),
	  	            		rSet.rs.getString("update_time")));
	            		
	          }
	        } catch (SQLException e) {
	          e.printStackTrace();
	        }
	      }
	      rSet.close();
	    return alist;
	}
	
	public int messageAdd(MessageEntity message) {
 		String sqlString="insert into message(create_time,name,phone,email,content) values ('"+message.getCreateTime()+"','"+message.getName()
 		  +"','"+message.getPhone()+"','"+message.getEmail()+"','"+message.getContent()+"')";
 		 int result= DBManager.executeUpdate(sqlString);
 		return result;
 	}
	
	  public int messageUpdate(MessageEntity mEntity) { 
		  String sqlString="update message set note='"+mEntity.getNote()+"',show_home='"+mEntity.getShowHome()+"',update_time='"+mEntity.getUpdateTime()+"' where id = '"+mEntity.getId()+"'"; 
		  int result= DBManager.executeUpdate(sqlString); 
		  return result; 
	  }
	 
	 
	 public int messageDelete(int id) {
			// TODO Auto-generated method stub
			String sqlString = "delete from message where id = '"+id+"'";
			int result = DBManager.executeUpdate(sqlString);
			return result;
		}
}
